package com.framework.loippi.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @ClassName DateTimeUtils
 * @Description 时间转换工具类
 * @Author fsociety
 * @Date 27/12/2019 下午3:37
 * @Version 1.0
 */
public class DateTimeUtils {
    /**
     * 将字符串转换成时间
     */
    public static Date convertString2Date(String format, String dateStr) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
        try {
            Date date = simpleDateFormat.parse(dateStr);
            return date;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**将时间转换成字符串
     * @param format
     * @param date
     * @return
     */
    public static String convertDate2String(String format,Date date) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
        return simpleDateFormat.format(date);
    }

    public static void main(String[] args) {
        System.out.println(convertDate2String("HH:mm:ss",new Date()));
    }

}
